package com.weixing.mall.provider.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.domain.Scene;
import com.weixing.mall.provider.model.dto.SceneDto;
import com.weixing.mall.provider.model.query.SceneQuery;
import com.weixing.mall.provider.service.ISceneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/8/6 9:05
 * @Version 1.0
 */
@RestController
@RequestMapping("scene")
@Api(value = "场景Api",tags = "场景")
public class SceneController extends BaseController {

    @Autowired
    private ISceneService sceneService;

    @ApiOperation(value = "查询")
    @GetMapping("")
    public Result list(SceneQuery sceneQuery){
        return ResultUtil.success(sceneService.findPage(initMpPage(),sceneQuery));
    }

    @ApiOperation(value = "添加")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(SceneDto sceneDto){
       /* try{
            Scene scene=   sceneService.getOne(new QueryWrapper<Scene>().eq("scene_name",sceneDto.getSceneName()));
            if(sceneDto.getId()==null&&scene!=null){
                return ResultUtil.error("场景名称已经存在请重新填写");
            }
          *//*  if(null!=scene&&scene.getSceneName().equals(sceneDto.getSceneName())&&sceneDto.getId()!=null){
                return ResultUtil.error("场景名称已经存在请重新填写！");
            }*//*
        }catch (Exception e){
            return ResultUtil.error("出现未知错误，请重新联系管理员！");
        }*/
        sceneService.save(sceneDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除场景")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "场景id",paramType = "path",dataType = "long")
    })
    @PostMapping("del/{id}")
    public  Result del(@PathVariable long id){
        return sceneService.removeById(id)? ResultUtil.success():ResultUtil.error();
    }

    @ApiOperation(value = "批量删除场景")
    @PostMapping("delAll/{ids}")
    public Result delAll(@PathVariable int ids[]){
        sceneService.deleteAll(ids);
        return ResultUtil.success();
    }
}
